package com.navinfo.platform.thousandkilo.service;

import com.navinfo.platform.common.service.ICommonService;
import com.navinfo.platform.common.service.ILoadDataChannel;
import com.navinfo.platform.common.service.ILoadDataService;
import com.navinfo.platform.common.service.impl.LoadDataFromHive;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public enum ThousandKiloLoadDataService implements ILoadDataService {
    // singleton
    INSTANCE;

    private ILoadDataChannel hiveChannel = LoadDataFromHive.INSTANCE;

    @Override
    public List<Object> loadData(SparkSession spark, Map<String, String> configMap) {
        String day = configMap.get(ICommonService.DAY_VALUE);
        String tripHql = configMap.get("hdfs.data.hql.trip");
        tripHql = String.format(tripHql, day);
        Dataset<Row> tripInfo = hiveChannel.readData(spark, tripHql);

        Dataset<Row> maxSectionByTmn = hiveChannel.readData(spark, configMap.get("hdfs.data.hql.maxSec"));

        List<Object> data = new ArrayList<>();
        data.add(tripInfo);
        data.add(maxSectionByTmn);
        return data;
    }
}
